﻿#include <iostream>
using namespace std;

// 两整数之和
// https://leetcode.cn/problems/sum-of-two-integers/description/
class Solution
{
public:
    int getSum(int a, int b)
    {
        while (b != 0)
        {
            int x = a ^ b; // 先算出无进位相加的结果
            unsigned int carry = (unsigned int)(a & b) << 1; // 算出进位
            a = x;
            b = carry;
        }
        return a;
    }
};

int main()
{
    int a = 18, b = 34;
    cout << Solution().getSum(a, b) << endl;
    return 0;
}